package chapter02

object Test07_DataTypeConversion {

  def main(args: Array[String]): Unit = {

    var a4: Byte = 12

    var b4: Short = 25

    val c4: Char = 'c'

    val result4: Int = a4 + b4

    val result44: Int = a4 + b4 + c4

    println(result4)
    println(c4)


    //将数据由高精度转换为低精度，就需要使用到强制转换
    val n1: Int = -2.9.toInt
    println(n1)


    //强制符号只针对于最近的操作数有效，往往会使用小括号提升优先级
    val n2: Int = 2.6.toInt + 3.7.toInt
    val n3: Int = (2.6 + 3.7).toInt

    println("n2" + n2)
    println("n3" + n3)


    //数值类型和String类型转换l

    // 数值转String
    var n: Int = 27
    var s: String = n + ""
    println(s)


    //String转数值
    val m: Int = "12".toInt
    val f: Float = "12.3".toFloat

    val f2: Int = "12.3".toDouble.toInt
    println(f2)
  }

}
